package com.example.yls.demoa;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;

public class StudentActivity extends AppCompatActivity {

    private EditText etNo;
    private EditText etName;
    private EditText etBirth;
    private EditText etPhone;
    private MyDataBaseHelper helper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student);
       etNo=findViewById(R.id.result_no);
       etName=findViewById(R.id.result_name);
       etBirth=findViewById(R.id.result_birth);
       etPhone=findViewById(R.id.result_phone);

        Intent intent = getIntent();
        String key= intent.getStringExtra("KEY");

        helper=new MyDataBaseHelper(StudentActivity.this);
        SQLiteDatabase db = helper.getReadableDatabase();
        String where = "no="+key;
        Cursor cursor = db.query("student", null, where, null, null, null, null);
        cursor.moveToFirst();
        String name=cursor.getString(2);
        String birth=cursor.getString(3);
        String phone=cursor.getString(4);

        etNo.setText(key);
        etName.setText(name);
        etBirth.setText(birth);
        etPhone.setText(phone);
    }
}
